<?php

   class Music extends Admin{
    	
		public function __construct(){
			parent::__construct();
			if(!$_SESSION['U']['adminid']){
				$this->showmessage("您还未登录","?m=Admin/Login" ,2000, "管理员登录");
			}else{
				$this->_T['U'] = $_SESSION['U'];
				$this->template();
			}
		}
		
		
		
		public function Index(){
			$this->mod = "MusicList";
			$page = new Page(8,"select * from `ntwt_music`");
			$this->_T['PageList']['con']      = $page->content;
			$this->_T['PageList']['rowNum'] = $page->num;
			$this->_T['PageList']['pageOne']  = $page->first_page;
			$this->_T['PageList']['pageLast'] = $page->last_page;
			$this->_T['PageList']['pageVal']  = $page->pageval;
			$this->_T['PageList']['pagePre']  = $page->pageval-1;
			$this->_T['PageList']['pageNext'] = $page->pageval+1;
			$this->template("parent");
		}
		
		public function Edit(){
			$this->mod = "Form";
			$this->fun = "edit";
			$mid = $_GET['mid'];
			$this->_getEditor();
			$this->_T['music'] = DB::fetch_row("select * from `ntwt_music` where `mid`='{$mid}'");
			$this->template("parent");
		}
		
		public function Update(){
			$data = array();
			$data['title'] = $_POST['title'];
			$data['con']   = $_POST['con'];
			$data['updatetime'] = date('Y-m-d H:i:s');
			$condition = array();
			$condition['mid'] = $_POST['mid'];
			if(DB::update("ntwt_music", $data, $condition)){
				$this->showmessage("编辑成功", "?m=Admin/Music/Index", 2000, "返回乐谱列表");
			}
			$this->showmessage("编辑失败","goback" ,2000, "返回");
		}
		
		public function Add(){
			$this->mod = "Form";
			$this->_getEditor();
			$this->_T['fun'] = "Add";
			$this->template("parent");
		}
		
		public function Insert(){
			$music = array();
			$music['title'] = $_POST['title'];
			$music['con']   = $_POST['con'];
			$music['updatetime'] = date('Y-m-d H:i:s');
			if(DB::insert("ntwt_music", $music)){
				$this->showmessage("添加成功", "?m=Admin/Music/Index", 2000, "返回乐谱列表");
			}
			$this->showmessage("添加失败","goback" ,2000, "返回");
		}
		
		public function Delete(){
			$mid = $_GET['mid'];
			$condition = array();
			$condition['mid'] = $mid;
			if(DB::delete("ntwt_music", $condition)){
				$this->showmessage("删除成功", "?m=Admin/Music/Index", 2000, "返回乐谱列表");
			}
			$this->showmessage("删除失败","goback" ,2000, "返回");
		}
		
		private function _getEditor(){
			$editor = new Editor("con");
			$editor->setmaxWords(5000);
			$this->_T['editorHeader'] = $editor->getHeaderHtml();
			$this->_T['editor'] = $editor->getEditorHtml();
		}

   }




?>